package com.ezops.dao.facade;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ezops.dao.TradeClientDAO;
import com.ezops.dao.generics.dao.hibernate.GenericDAO;
import com.ezops.dao.generics.search.Search;
import com.ezops.models.TradeClient;

@Service
public class TradeClientDataTransferFacade extends
		DataTransferFacadeImpl<TradeClient> implements ITradeClientDataTransferFacade {

	@Autowired
	private TradeClientDAO dao;

	/* (non-Javadoc)
	 * @see com.ezops.dao.facade.ITradeClientDataTransferFacade#lookUp(java.lang.String)
	 */
	@Override
	public int lookUp(String name) {
		Search searchCriteria = new Search(TradeClient.class);
		searchCriteria.addFilterEqual("clientId", name.toLowerCase());
		// TODO : Remove parseInt later.
		return Integer.parseInt(((TradeClient) dao.search(searchCriteria)
				.get(0)).getId());
	}

	/* (non-Javadoc)
	 * @see com.ezops.dao.facade.ITradeClientDataTransferFacade#reverseLookUp(java.lang.Integer)
	 */
	@Override
	public String reverseLookUp(Integer clientId) {
		Search searchCriteria = new Search(TradeClient.class);
		searchCriteria.addFilterEqual("clientId", clientId);
		return ((TradeClient) dao.search(searchCriteria).get(0))
				.getClientName();
	}

	/* (non-Javadoc)
	 * @see com.ezops.dao.facade.ITradeClientDataTransferFacade#getAllAssets()
	 */
	@Override
	public List<TradeClient> getAllAssets() {
		return dao.findAll();
	}

	@Override
	public GenericDAO<TradeClient, Serializable> getDataAccessObject() {
		// TODO Auto-generated method stub
		return dao;
	}

}
